﻿<UserControl x:Class="BillsManager.Views.SuppliersView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:Caliburn="http://www.caliburnproject.org"
             xmlns:Commanding="clr-namespace:BillsManager.ViewModels.Commanding;assembly=BillsManager.ViewModels"
             xmlns:Controls="clr-namespace:BillsManager.Views.Controls"
             xmlns:DataTemplates="clr-namespace:BillsManager.Views.DataTemplates"
             xmlns:Models="clr-namespace:BillsManager.Models;assembly=BillsManager.Models"
             xmlns:ViewModels="clr-namespace:BillsManager.ViewModels;assembly=BillsManager.ViewModels"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:Loc="clr-namespace:BillsManager.Localization;assembly=BillsManager.Localization"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             MinWidth="200"
             Caliburn:Bind.AtDesignTime="True"
             d:DataContext="{d:DesignInstance Type=ViewModels:SuppliersViewModel,
                                              IsDesignTimeCreatable=True}"
             d:DesignHeight="250"
             d:DesignWidth="900"
             mc:Ignorable="d">

    <UserControl.Resources>
        <!--<ResourceDictionary Source="Dictionaries\Styles.xaml" />-->
        <ResourceDictionary Source="Themes\Themes.xaml" />
    </UserControl.Resources>

    <UserControl.Background>
        <Binding Mode="OneTime" Source="{StaticResource View.Background}" />
    </UserControl.Background>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="{StaticResource View.Region.Spacing.Normal}" />
            <!--<RowDefinition Height="Auto" />-->
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>

        <TextBlock FontSize="{StaticResource View.Region.Title.FontSize}"
                   FontWeight="{StaticResource View.Region.Title.FontWeight}"
                   Foreground="{StaticResource View.Region.Title.Foreground}"
                   Text="{Loc:Translate Suppliers}"
                   Visibility="{StaticResource View.Region.Title.Visibility}" />

        <!--<Rectangle Grid.Row="2"
                   Height="1"
                   HorizontalAlignment="Stretch"
                   VerticalAlignment="Center"
                   Fill="{StaticResource View.Foreground.Disabled}" />-->

        <Controls:ListViewEx x:Name="lsvSuppliers"
                             Grid.Row="3"
                             AlternationCount="0"
                             ItemDoubleLeftClickCommand="{Binding ShowSupplierDetailsCommand}"
                             ItemDoubleLeftClickCommandParameter="{Binding SelectedSupplierViewModel}"
                             ItemsSource="{Binding FilteredSupplierViewModels,
                                                   IsAsync=True}"
                             SelectedItem="{Binding SelectedSupplierViewModel}"
                             SelectionMode="Single"
                             VirtualizingPanel.IsVirtualizing="True"
                             VirtualizingPanel.VirtualizationMode="Recycling">

            <!--
            <ListView.ItemTemplate>
            <DataTemplate>
            <DataTemplates:SupplierDataTemplate />
            </DataTemplate>
            </ListView.ItemTemplate>
            -->

            <ListView.View>
                <GridView>
                    <GridViewColumn Width="Auto" Header="{Loc:Translate Name}">
                        <GridViewColumn.HeaderTemplate>
                            <DataTemplate>
                                <TextBlock FontWeight="{StaticResource View.Region.Title.FontWeight}" Text="{Loc:Translate Name}" />
                            </DataTemplate>
                        </GridViewColumn.HeaderTemplate>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Border x:Name="obg"
                                        Margin="0 -5"
                                        HorizontalAlignment="Stretch"
                                        VerticalAlignment="Stretch"
                                        CornerRadius="{StaticResource Control.Border.CornerRadius}"
                                        Padding="5">
                                    <TextBlock x:Name="text" Text="{Binding Name}" />
                                </Border>

                                <DataTemplate.Triggers>

                                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListViewItem}}, Path=IsSelected}" Value="True">
                                        <Setter TargetName="obg" Property="CornerRadius">
                                            <Setter.Value>
                                                <CornerRadius BottomLeft="0"
                                                              BottomRight="0"
                                                              TopLeft="0"
                                                              TopRight="0" />
                                            </Setter.Value>
                                        </Setter>
                                    </DataTrigger>

                                    <DataTrigger Binding="{Binding ObligationState}" Value="{x:Static Models:Obligation.Creditor}">
                                        <Setter TargetName="obg" Property="Background" Value="{StaticResource Obligation.Creditor.Brush}" />
                                        <Setter TargetName="text" Property="Foreground" Value="{StaticResource Button.Foreground.Normal}" />
                                    </DataTrigger>

                                    <DataTrigger Binding="{Binding ObligationState}" Value="{x:Static Models:Obligation.Debtor}">
                                        <Setter TargetName="obg" Property="Background" Value="{StaticResource Obligation.Debtor.Brush}" />
                                        <Setter TargetName="text" Property="Foreground" Value="{StaticResource Button.Foreground.Normal}" />
                                    </DataTrigger>

                                    <DataTrigger Binding="{Binding ObligationState}" Value="{x:Static Models:Obligation.Unbound}">
                                        <!--  <Setter TargetName="text" Property="Visibility" Value="Collapsed" />  -->
                                    </DataTrigger>

                                </DataTemplate.Triggers>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                    <!--
                    <GridViewColumn Width="100"
                    Header="{Loc:Translate Obligation}">
                    <GridViewColumn.CellTemplate>
                    <DataTemplate>
                    -->
                    <!--
                    <Path Name="obg"
                    Data="{StaticResource Obligation.Null.Geometry}"
                    Fill="{StaticResource Obligation.Unbound.Brush}"
                    Stretch="Uniform"
                    Height="{StaticResource View.FontSize}"
                    Width="{StaticResource View.FontSize}"
                    VerticalAlignment="Center" />
                    -->
                    <!--
                    <Border x:Name="obg"
                    Margin="-5"
                    HorizontalAlignment="Stretch"
                    VerticalAlignment="Stretch"
                    CornerRadius="{StaticResource Control.Border.CornerRadius}"
                    Padding="5">
                    <TextBlock x:Name="text"
                    Text="{Binding ObligationStateString}" />
                    </Border>

                    <DataTemplate.Triggers>

                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListViewItem}}, Path=IsSelected}"
                    Value="True">
                    <Setter TargetName="obg" Property="CornerRadius" Value="0" />
                    </DataTrigger>

                    <DataTrigger Binding="{Binding ObligationState}"
                    Value="{x:Static ViewModel:Obligation.Creditor.Brush}">
                    <Setter TargetName="obg" Property="Background" Value="{StaticResource Obligation.Creditor.Brush}" />
                    <Setter TargetName="text" Property="Foreground" Value="{StaticResource Button.Foreground.Normal}" />
                    </DataTrigger>

                    <DataTrigger Binding="{Binding ObligationState}"
                    Value="{x:Static ViewModel:Obligation.Debtor.Brush}">
                    <Setter TargetName="obg" Property="Background" Value="{StaticResource Obligation.Debtor.Brush}" />
                    <Setter TargetName="text" Property="Foreground" Value="{StaticResource Button.Foreground.Normal}" />
                    </DataTrigger>

                    <DataTrigger Binding="{Binding ObligationState}"
                    Value="{x:Static ViewModel:Obligation.None}">
                    <Setter TargetName="text" Property="Visibility" Value="Collapsed" />
                    </DataTrigger>

                    </DataTemplate.Triggers>

                    </DataTemplate>
                    </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="Auto"
                    DisplayMemberBinding="{Binding Notes}"
                    Header="{Loc:Translate Notes}" />
                    -->
                </GridView>
            </ListView.View>

            <ListView.ContextMenu>
                <ContextMenu>

                    <MenuItem Command="{Binding SelectedSupplierViewModel.AddBillCommand, Mode=OneWay}" Header="{Loc:Translate AddBill}">
                        <MenuItem.Icon>
                            <Controls:AutoGreyableImage Source="Images/bills/bill-add-24.png" />
                        </MenuItem.Icon>
                    </MenuItem>

                    <MenuItem Command="{Binding ShowSuppliersBillsCommand,
                                                Mode=OneWay}"
                              CommandParameter="{Binding SelectedSupplierViewModel}"
                              Header="{Loc:Translate ShowBills}">
                        <MenuItem.Icon>
                            <Controls:AutoGreyableImage Source="Images/generic/search-16.png" />
                        </MenuItem.Icon>
                    </MenuItem>

                    <Separator />

                    <MenuItem Command="{Binding AddNewSupplierCommand, Mode=OneWay}" Header="{Loc:Translate Add}">
                        <MenuItem.Icon>
                            <Controls:AutoGreyableImage Source="Images/generic/add-16.png" />
                        </MenuItem.Icon>
                    </MenuItem>

                    <MenuItem Command="{Binding EditSupplierCommand,
                                                Mode=OneWay}"
                              CommandParameter="{Binding SelectedSupplierViewModel}"
                              Header="{Loc:Translate Edit}">
                        <MenuItem.Icon>
                            <Controls:AutoGreyableImage Source="Images/generic/edit-16.png" />
                        </MenuItem.Icon>
                    </MenuItem>

                    <MenuItem Command="{Binding DeleteSupplierCommand,
                                                Mode=OneWay}"
                              CommandParameter="{Binding SelectedSupplierViewModel}"
                              Header="{Loc:Translate Delete}">
                        <MenuItem.Icon>
                            <Controls:AutoGreyableImage Source="Images/generic/delete-16.png" />
                        </MenuItem.Icon>
                    </MenuItem>

                    <Separator />

                    <MenuItem Command="{Binding ShowSupplierDetailsCommand,
                                                Mode=OneWay}"
                              CommandParameter="{Binding SelectedSupplierViewModel}"
                              Header="{Loc:Translate Details}">
                        <MenuItem.Icon>
                            <Controls:AutoGreyableImage Source="Images/generic/details-16.png" />
                        </MenuItem.Icon>
                    </MenuItem>

                    <MenuItem Command="{Binding CopyEMailCommand,
                                                Mode=OneWay}"
                              CommandParameter="{Binding SelectedSupplierViewModel}"
                              Header="{Loc:Translate CopyEmail}">
                        <MenuItem.Icon>
                            <Controls:AutoGreyableImage Source="Images/generic/email-16.png" />
                        </MenuItem.Icon>
                    </MenuItem>

                </ContextMenu>
            </ListView.ContextMenu>

        </Controls:ListViewEx>

    </Grid>

</UserControl>